var express = require('express');
var router = express.Router();
var lyby = require('../util');
var http = require('http');
var fs = require("fs");
var request = require('request');
var url = require('url');
var querystring = require('querystring');
var async = require("async");

var user_class = require('./users');
var filter = user_class;
var layoutStr = 'lyby/layout';

router.post('/gic/uploadPic.html',function (req, res, next) {
	setTimeout(function () {
		res.json(


			{"message":"sucess","status":"200","data":{"lookUrl":{"p1":"http://c.shijue.me/picurl/7ac4e93a21954556b4720be4fcc3ca06---jpg.jpg?code=52628e10f13a01cf"},"graphicalStyle":1,"updateTime":1467969778238,"createdTime":1467969778238,"canSubmit":false,"width":4192,"state":0,"propertyRelease":0,"url":"http://oss-cdn.500px.me/7ac4e93a21954556b4720be4fcc3ca06.jpg","id":"7ac4e93a21954556b4720be4fcc3ca06","modelRelease":0,"height":3104,"userId":"fb64393244cf0b3e23918a78d90e99920","fileName":"P50321-142043.jpg","assetFamily":2,"draftBoxId":"d0acdea957704ec7a14b506723ffebdf","rightType":0}}

		)
	},5000)
});
router.get('/gic/draft/getCurrentDraftBox',function (req, res, next) {
	res.json({
		"message" : "sucess",
		"status" : "200",
		"data" : {
			"assetFamily" : 1,
			"autoMeta" : true,
			"canSubmitCount" : 0,
			"createdTime" : 1467860693000,
			"graphicalStyle" : 1,
			"id" : "58dae2ae2c8d4ed7b9009073e310436f",
			"state" : -1,
			"totalCount" : 0,
			"updateTime" : 1467860693000,
			"userId" : "fb64393244cf0b3e23918a78d90e99920"
		}
	})
})
router.get('/otherInterface/*',function (req, res, next) {
    var pathnameStr = '';
    for(var key in req.params){
        pathnameStr += '/'+ req.params[key];
    }
    var urlStr = url.format({
        protocol: 'http',
        host: 'vcg-design.shijue.me',
        pathname: '/community'+pathnameStr,
        search: querystring.stringify(req.query)
    });
    console.log(urlStr)
    request.get({
        url : urlStr,
        headers: {
            'X-Requested-With':'XMLHttpRequest',
            Cookie : '_ga=GA1.2.167994531.1508736397; Hm_lvt_78ea451fc4ef02358930eaa6448bfcaf=1515403911,1515580847; dc_session_id=1516087130990; token=Token-36442522-30a2-4db7-8e6e-0bc0632e0d25; userId=15f8dbf6d417aa75823d32e6906c14051_d; Hm_lvt_7acfbc4d7bdb93be5cf0ee26c52160bf=1515574142,1516087131,1516427186,1516427228; _gid=GA1.2.1871852524.1516686177; _gat=1; Hm_lpvt_7acfbc4d7bdb93be5cf0ee26c52160bf=1516690238; dc_tos=p2zxod',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
            Host: 'vcg-design.shijue.me',
            Referer: 'vcg-design.shijue.me'
        },
        //qs : req.query,
        json : true
    },function(error,msg,data){
        res.json(data);
    });
});
router.get('/*',function (req, res, next) {
	var pathnameStr = '';
	for(var key in req.params){
		pathnameStr += '/'+ req.params[key];
	}
	var hostStr = 'zenchina.org';
	var urlStr = url.format({
		protocol: 'http',
		host: hostStr,
		pathname: '/community'+pathnameStr,
		search: querystring.stringify(req.query)
	});
	console.log(urlStr)
	request.get({
		url : urlStr,
		headers: {
            'X-Requested-With':'XMLHttpRequest',
            Cookie : local.cookie || req.headers.cookie,
			'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
			Host: hostStr,
			Referer: hostStr
		},
		//qs : req.query,
		json : true
	},function(error,msg,data){
		res.json(data);
	});
});

router.post('/*',function (req, res, next) {
    var pathnameStr = '';
    for(var key in req.params){
        pathnameStr += '/'+ req.params[key];
    }
    var urlStr = url.format({
        protocol: 'http',
        host: 'zenchina.org',
        pathname: '/community'+pathnameStr,
        search: querystring.stringify(req.query)
    });
    console.log(urlStr)
    request.post({
        url : urlStr,
        headers: {
            'requestSource': 'shijue',
            // Cookie:'dc_tos=ofnbwq; dc_session_id=1477470986602; uaid=f3a12e804f1c4f698d4b54b31be6e5e4; adobe_adv_load=true; token=Token-4f066887-5ed8-4196-8691-7f3eea611658; JSESSIONID=30ygpnjld8rxurne80nfpuqn; Hm_lvt_7acfbc4d7bdb93be5cf0ee26c52160bf=1477382062,1477382065,1477444499,1477470548; Hm_lpvt_7acfbc4d7bdb93be5cf0ee26c52160bf=1477470983',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
            Host: 'vcg-design.shijue.me',
            Referer: 'vcg-design.shijue.me'
        },
        form : req.body,
        json : true
    },function(error,msg,data){
        res.json(data);
    });
});

module.exports =  router;
